<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数组的双向绑定</title>
  </head>
  <body></body>
  <script>
    let obarr = [];
    // copy数组，防止污染全局数组方法
    const arrayProto = Array.prototype;
    const arrayMethods = Object.create(arrayProto);
    Object.defineProperty(arrayMethods, "push", {
      value: function () {
        // 缓存原生方法 之后调用
        const orginal = arrayProto["push"];
        let args = Array.from(arguments);
        orginal.apply(this, args);
      },
    });
    obarr.__proto__ = arrayMethods;
    arrayMethods.push(123);
    arrayMethods.push(22);
  </script>
</html>
